﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;

namespace WebStoreClient
{
    public class ErrorMsg
    {
        public ErrorMsg() { }
        public ErrorMsg(HttpResponseMessage msg)
        {
            if (msg != null && !msg.IsSuccessStatusCode)
            {
                if(msg.StatusCode==System.Net.HttpStatusCode.Forbidden)
                {
                    throw new WsForbiddenException("无使用权限");
                }else if (msg.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                {
                    throw new WsNeedLoginException("请重新登陆");
                }else if(msg.StatusCode==System.Net.HttpStatusCode.BadRequest || msg.StatusCode==System.Net.HttpStatusCode.InternalServerError)
                {
                    if (msg.Content != null)
                    {
                        var json = msg.Content.ReadAsStringAsync().Result;
                        try
                        {
                            var a = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorMsg>(json);

                        }
                        catch { }
                        this.Message = "系统异常";
                        this.ExceptionMessage = json;
                    }
                }
            }
        }
        public string Message { get; set; }
        public string ExceptionMessage { get; set; }
        public string ExceptionType { get; set; }
        public string StackTrace { get; set; }
    }
}
